Structural sharing topic
When new data arrives, replaceEqualDeep keeps the parts equal to the cached data as the same instances, so identical checks and rebuilds can skip what did not change. StructurallyShareable lets your own value classes take part; StructuralSharing and noStructuralSharing configure it per query.
Classes
- A value class that structural sharing may walk into.
Functions
-
noStructuralSharing<
TQueryData> () → StructuralSharing< Structural sharingTQueryData> -
The opt-out for QueryOptions.structuralSharing: every write keeps the
incoming value, so every refetch reports a new instance, and so does every
select. TanStack Query spells thisstructuralSharing: false. -
replaceEqualDeep<
T> (Object? previous, T next, [int depth = 0]) → T Structural sharing -
Returns
previouswhennextis deep-equal to it, and otherwisenextwith every deep-equal part swapped for the instancepreviousalready held. This is the default structural sharing of every query, and the reason a refetch that brings back the same data does not rebuild anything: unchanged data keeps its instance, soidenticalchecks and==short-circuits downstream stay cheap and true.
Typedefs
-
StructuralSharing<
TQueryData> = TQueryData Function(TQueryData? previous, TQueryData next) Structural sharing - Decides what is written into the cache when new data arrives, given what was there before.